1 using System.Collections;
2 using
System.Collections.Generic;
3 using
UnityEngine;
4 using
UnityEngine.UI;
5
6 public
class EnemyHealth : MonoBehaviour {
7
8     
public Slider health;
9     
public int maxHealth;
10     
public GameObject explosion, coin;
11
12     
private bool spawn;
13
14     
void Awake(){
15         health.maxValue = maxHealth;
16         health.
value = maxHealth;
17     }
18
19     
// Use this for initialization
20     
void Start () {
21         
22     }
23     
24     
public void Health(int damage){
25         
if(!health.gameObject.activeInHierarchy){
26             health.gameObject.SetActive (
true);
27         }
28
29         
if(health.value > 0){
30             health.
value -= damage;
31         }
32
33         
if(health.value == 0){
34             Destroy (gameObject);
35             
if(!spawn){
36                 spawn =
true;
37                 Instantiate (explosion, transform.position, Quaternion.identity);
38                 Instantiate (coin, transform.position, Quaternion.identity);
39             }
40
41         }
42     }
43         
44
45 }


Use this for initialization



Gõ tìm kiếm nhanh...